<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="-1">
<title>欢迎页面</title>
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/common/css/layout.css" />
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/common/css/common.css" />
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/management/css/update.css" />
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath}/common/javascript/plugins/boxy/boxy.css" />
<script type="text/javascript"
	src="${pageContext.request.contextPath}/common/javascript/jquery.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/common/javascript/plugins/boxy/jquery.boxy.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/common/javascript/plugins/jquery.extcloudSlideMenu.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/management/javascript/operation.js"></script>
<%@include file="/WEB-INF/view/commonJavascriptVar.jsp"%>
<script type="text/javascript">
$(function() {
	$("li.layout_search_pull_ss a").extcloudSlideMenu({
		init_hideMenu: true ,
		speed: "fast"
	}) ;
});

function deleteItem(equipmentId,categoryId,aElement) {
	var callback = function(){
		$(aElement).parent().remove();
	};
	ajaxDelete(equipmentId,categoryId,callback) ;
}

function addItem(categoryId,categoryDesc) {
	var equipmentId = '${equipment.equipmentId}';
	var callback = function(){
		$("#categoriesDiv").append("<div>" + categoryDesc + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:void(0);' onclick=javascript:deleteItem('"+equipmentId+"','"+categoryId+"',this)>删除</a></div>"); 
	};
	ajaxAdd(equipmentId,categoryId,callback) ;
}

function ajaxAdd(equipmentId,categoryId,callback) {
	var ajaxParams = {ss:Math.random*100000} ;
	var url = context + "/management/cte/ajaxadd/"+categoryId+"_" + equipmentId ;
	$.get(url, ajaxParams,
			function(data, textStatus, jqXHR) {
				if (textStatus == "success") {
					if(data.error) {
						alert(data.info) ;
						return false;
					} else if(data.success) {
						callback();
						alert(data.info) ;
						return true ;
					} else {
						alert("出现未知异常.") ;
						return false ;
					}
				}
	}, "json");
}

function ajaxDelete(equipmentId,categoryId,callback) {
	var ajaxParams = {ss:Math.random*100000} ;
	var url = context + "/management/mmc/ajaxdelete/"+categoryId+"_" + equipmentId ;
	$.get(url, ajaxParams,
			function(data, textStatus, jqXHR) {
				if (textStatus == "success") {
					if(data.error) {
						alert(data.info) ;
						return false;
					} else if(data.success) {
						callback();
						alert(data.info) ;
						return true ;
					} else {
						alert("出现未知异常.") ;
						return false ;
					}
				}
	}, "json");
}
</script>
<script type="text/javascript">
var propsData = null ;
function addProperty() {
	if(propsData!=null) {
		ddd(propsData);
		return ;
	}

	var url = "${pageContext.request.contextPath}/management/equipment/property/ajaxgetpropertys" ;
	var callback = function(data) {
		propsData = data.objects ;
		ddd(propsData);
	}
	ajaxGetProps(url,callback) ;
	return  propsData;
}
function getOptionsStr(props) {
	var str = "" ;
	for(var i = 0 ;i<props.length;i++) {
		str += "<option value='"+props[i].propertyId+"'>"+props[i].propertyName+"</option>" ;
	}
	return str ;
}
function ddd(propsData) {
	var props = propsData;
	var propsOptionsStr = getOptionsStr(props);
	var selectStr = "<select name='property'>"+propsOptionsStr+"</select>";
	var str = "<tr><td><input style='display:none;' type='checkbox' name='ids' />"+selectStr+"</td>"+
		"<td><input name='min' /></td><td><input name='max' /></td><td><input name='sort' value='1' /></td><td><a href='javascript:void(0);' onclick='javascript:complete();'>完成</a></td></tr>" ;
	$("#propertyTable").append(str);
}

function ajaxGetProps(url,callback) {
	var ajaxParams = {
			ssssss : Math.random() * 100000
		};
		$.get(url, ajaxParams, function(data, textStatus, jqXHR) {
			if (textStatus == "success") {
				if (data.error) {
					alert(data.info);
					return false;
				} else if (data.success) {
					callback(data);
					return true;
				} else {
					alert("出现未知异常.");
					return false;
				}
			}
		}, "json");
}
</script>
</head>
<body>
<div id="layoutAll">
<table cellpadding="0" cellspacing="0" width="100%" id="layout_content">
	<tr>
		<td height="100" valign="top">
		<div id="layout_title">
		<h4>前缀修改</h4>
		</div>
		<div id="layout_search">
		<p>&nbsp;</p>
		</div>
		<div id="layout_search_pull">
		<ul>
			<li><a id="backSubmit" href="#"
				onclick="if(confirm('确定修改?')){$('#backForm').submit();}">确定修改</a></li>
			<li><img
				src="${pageContext.request.contextPath}/common/images/menufg.jpg" />
			</li>
			<li><a href="javascript:void(0);"
				onclick="javascript:addProperty();">增加属性</a></li>
			<li><img
				src="${pageContext.request.contextPath}/common/images/menufg.jpg" />
			</li>
			<li><a id="backSubmit"
				href="${pageContext.request.contextPath}/management/equipment/prefix/index">取消并返回列表</a></li>
			<li><img
				src="${pageContext.request.contextPath}/common/images/menufg.jpg" /></li>
			<li class="layout_search_pull_ss"><a href="#"><img
				src="${pageContext.request.contextPath}/common/images/menu_up.gif" /></a></li>
		</ul>
		</div>
		</td>
	</tr>
	<tr>
		<td valign="top">
		<div id="layout_content_body">
		<h1 align="center">前缀修改</h1>
		<center>
		<form id="backForm"
			action="${pageContext.request.contextPath}/management/equipment/prefix/update/${prefix.prefixId}"
			method="post">
		<table align="center" width="90%" border="1px" bordercolor="#D4D4D4"
			cellspacing="0px">
			<tr>
				<td width=100><label for="prefixName">名称</label></td>
				<td><input name="prefixName" type="text"
					value="${prefix.prefixName}" /></td>
			</tr>
			<tr>
				<td width><label for="prefixDescription">描述</label></td>
				<td><input name="prefixDescription" type="text"
					value="${prefix.prefixDescription}" /></td>
			</tr>
			<tr>
				<td><label for="prefixLevel">等级</label></td>
				<td><input name="prefixLevel" type="text" id="prefixLevel"
					value="${prefix.prefixLevel}" /></td>
			</tr>
			<tr>
				<td><label for="prefixKeywords">关键字</label></td>
				<td><input id="prefixKeywords" name="prefixKeywords"
					value="${prefix.prefixKeywords}" /></td>
			</tr>
			<tr>
				<td colspan="2"><label for="prefixKeywords">属性</label></td>
			</tr>
			<tr>
				<td colspan="2">
				<table id="propertyTable" align="center" width="50%" border="1px"
					bordercolor="#D4D4D4" cellspacing="0px">
					<thead>
						<tr>
							<th width=100>属性名</th>
							<th>最小值</th>
							<th>最大值</th>
							<th>排序</th>
							<th width=50>操作</th>
						</tr>
					</thead>
					<c:forEach items="${prefix.prefixValues}" var="prefixValue"
						varStatus="status">
						<tr>
							<td><input style="display: none;" name="ids" type="checkbox"
								value="${prefixValue.prefixValueId}" />
							${prefixValue.property.propertyName}</td>
							<td>${prefixValue.min}</td>
							<td>${prefixValue.max}</td>
							<td>${prefixValue.sort}</td>
							<td><a href="javascript:void(0);"
								onclick="javascript:del();">删除</a></td>
						</tr>
					</c:forEach>
				</table>
				</td>
			</tr>
		</table>

		</form>
		</center>
		</div>
		</td>
	</tr>
</table>
</div>
</body>
</html>